package com.ctrip.ibu.permissions.security.controller;

import com.ctrip.ibu.permissions.common.api.ResponseData;
import com.ctrip.ibu.permissions.security.dto.AuthDto;
import com.ctrip.ibu.permissions.security.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description
 *
 * @author r.shi 2020/02/26 15:53
 */
@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @Autowired
    AuthService authService;

    @PostMapping("/login")
    public ResponseData login(@RequestBody AuthDto dto) {
        return ResponseData.success(authService.login(dto.getUsername(), dto.getPassword()));
    }

    @PostMapping("/registry")
    public ResponseData registry(@RequestBody AuthDto user) {
        authService.registry(user);
        return ResponseData.success();
    }

    @DeleteMapping("/logout")
    public ResponseData logout(){
        authService.logout();
        return ResponseData.success();
    }

    @GetMapping( "/info")
    public ResponseData info(){
        return ResponseData.success(authService.info());
    }

}
